/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gs.coursera.algorithms.core.graph.ui;

import com.gs.coursera.algorithms.core.graph.Edge;
import com.gs.coursera.algorithms.core.graph.Graph;
import com.gs.coursera.algorithms.core.graph.Vertex;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

/**
 *
 * @author Sabuj
 */
public class AdjacencyListPanel<T, W extends Comparable<W>> extends JPanel{

    private Graph<T, W> graph;
    
    public AdjacencyListPanel(Graph<T, W> graph) {
        this.graph = graph;
        setBackground(Color.WHITE);
        setMinimumSize(new Dimension(400, 400));
        setPreferredSize(new Dimension(400, 400));
    }

    @Override
    public void paint(Graphics g) {
        if(null == g)
            return;
        Graphics2D g2 = (Graphics2D) g;
        
        
        int x = 10;
        int y = 10;
        int vH = 15;
        int vW = 70;
        if(graph != null && graph.getVertexCount() > 0){
            for(Vertex<T, W> v : graph.getVertices()){
                x = 10;
                y = y + vH + 5;
                
                g2.setColor(Color.BLACK);
                g2.drawString("" + v.getVertexNumber(), 
                        x, y);
                if(v.getAdjacencyList() != null && v.getAdjacencyList().size() > 0){
                    g2.setColor(Color.BLUE);
                    for(Edge<T,W> e: v.getAdjacencyList()){
                        x = x + vW + 5;
                        g2.drawString("" + e.getEndVertex().getVertexNumber() 
                        		+ "( " + e.getWeight() + " )", 
                                x, y);
                    }
                }
            }
        }
        
    }
    
    
    
    
}
